package com.atguigu.gulimall.order.config;

import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Configuration
public class OrderFeignConfig {

    @Bean
    public RequestInterceptor cookieRequestInterceptor() {

        return template -> {
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
            String cookie = attributes.getRequest().getHeader("Cookie");
            template.header("Cookie", cookie);
        };
    }
}
